import { Table, Form, Input } from 'antd';
import Cls from 'classnames';
import { AllotManageContext, IAllotActionEnum } from '../mconfig';
import { useContext, useEffect, useMemo, useState } from 'react';
import { openMaterielColumns } from '../mconfig';
import { getLoadMapList, getSelectDataMapList, getTenantID } from '@/utils';
import { ILoadMapTypeAll } from '@/common';
// import Input from 'rc-input';

export const UpdateMaterielView: React.FC<any> = ({ openMaterialModalStatus, pageType, openProperty }) => {
  // /**  获取数据字典 */
  const { loadMapInfo, mapLoading } = getLoadMapList([
    `${getTenantID()}${ILoadMapTypeAll.ASSET_TYPE}`, //资产类型
  ]);
  // /** 资产类型 */
  const assetTypeList = getSelectDataMapList(loadMapInfo?.[`${getTenantID()}${ILoadMapTypeAll.ASSET_TYPE}`], 'name', 'id', true);

  const { materielList, allotDispatch } = useContext(AllotManageContext);

  const delSelectRow = (record) => {
    // 取消仓库的选中材料列表
    const arr = materielList.filter((item) => {
      return item.id !== record.id;
    });
    allotDispatch({
      type: IAllotActionEnum.CANCEL_MATERIEL,
      payload: arr,
    });
  };

  /** 表格行配置 */
  const columns: Record<string, any>[] = useMemo(() => {
    return openMaterielColumns(openMaterialModalStatus, delSelectRow, pageType, openProperty);
  }, [materielList]);

  // useEffect(() => {}, [materielList]);

  return (
    <div className={Cls('list-table', 'descriptionsType-tableSty')} style={{ marginTop: '10px' }}>
      <Table
        bordered
        size="small"
        expandable={{
          expandedRowRender: (record) => (
            <div>
              <Form.Item label="调剂资产" labelCol={{ span: 2 }}>
                {record?.checkMaterialList?.map((item) => (
                  <Input disabled value={item?.assetCode} style={{ marginBottom: '10px', width: '260px', marginRight: '10px' }}></Input>
                ))}
              </Form.Item>
            </div>
          ),
          rowExpandable: (record) => record?.checkMaterialList && record?.checkMaterialList.length > 0,
        }}
        dataSource={materielList}
        columns={columns}
        rowKey={(res) => res?.id}
        scroll={{ x: 1400, y: '' }}
        pagination={false}
      />
    </div>
  );
};
